<template>
    <div>
        <!-- 滑动bar区域 -->
        <div id="slider" class="mui-slider">
            <div id="sliderSegmentedControl" class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted">
                <div class="mui-scroll">
                    <span
                    v-for="item in imgCategory" 
                    :key="item.id" 
                    @click="getImgByCategory(item.id)" 
                    :class="['mui-control-item',item.id===0?'mui-active':'']" data-wid="tab-top-subpage-1.html">
                        {{item.title}}
                    </span>
                </div>
            </div>
        </div>
        <!-- 图片懒加载区域---mintUI -->
        <ul class="imglistarea">
            <router-link tag="li"
            v-for="item in imglist" 
            :key="item.id"
            :to="'/home/photolist/'+item.id">
                <img v-lazy="item.img_url">
                <div class="info">
                    <h1 class="info-title">{{item.title}}</h1>
                    <div class="info-content">{{item.zhaiyao}}</div>
                </div>
            </router-link>
        </ul>
    </div>
</template>

<script>
import mui from '../../../lib/mui/js/mui.js'

export default {
    data:function(){
        return {
            imgCategory:[],
            imglist:[],            
        }
    },
    created:function(){
        this.getImgCategory();
        this.getImgByCategory(0);
    },
    mounted() {
        // 当此钩子函数执行的时候，我们才可以进行控件或插件的初始化工作；
        mui(".mui-scroll-wrapper").scroll({
        deceleration: 0.0005 //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006
        })
    },
    methods:{
        getImgCategory:async function () {
            const {data}=await this.$http.get('/api/getimgcategory');
            console.log(data);
            if(data.status===0) this.imgCategory=data.message;
            this.imgCategory.unshift({title:"全部",id:0})
        },
        getImgByCategory:async function(cateid){
            const {data} = await this.$http.get('/api/getimages/'+cateid);
            console.log(data);
            if(data.status===0) this.imglist=data.message;
        }
    },
}
</script>

<style lang="scss" scoped>
.mui-slider{
    // 提高流畅度
    touch-action: pan-x;
}
.imglistarea{
    // background: #000;
    margin: 0;
    padding: 10px;
    li{
        position: relative;
        text-align: center;
        background-color: rgb(85, 83, 83);
        box-shadow: 0 0 10px #000;

        &+li{
            margin-top: 10px;
        }

        img[lazy="loading"] {
            width: 40px;
            height: 300px;
            margin: auto;
        }

        img{
            width: 100%;
            vertical-align: middle;
        }

        .info{
            position: absolute;
            bottom: 5px;
            width: 394px;
            max-height: 88px;
            overflow: hidden;
            text-overflow: ellipsis;
            color:#fff;
            background-color: rgba($color: #000000, $alpha: 0.4);
            text-align: left;
            .info-title{
                font-size: 15px;
            }

            .info-content{
                font-size: 12px;
                text-indent: 2em;
            }
        }
    }
}
</style>



